package com.treeroot.springbootwithelastic.com.treeroot.es.config;

import lombok.Data;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;

import org.elasticsearch.client.RestClientBuilder;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.config.AbstractElasticsearchConfiguration;


/**
 * @author treeRoot
 * @Description: 配置类
 */
@Configuration
@Data

public class EsConfig extends AbstractElasticsearchConfiguration {

    @Value("${esconfig.host}")
    private String host;
    @Value("${esconfig.port}")
    private Integer port;
    @Value("${esconfig.userIndex}")
    private String userIndex;


    @Override
    public RestHighLevelClient elasticsearchClient() {
        RestClientBuilder builder = RestClient.builder(new HttpHost(host, port));
        return new RestHighLevelClient(builder);
    }


}
